package data;

public class Gene implements Comparable<Gene> {

	@Override
	public int compareTo(Gene g) {
		if (g==null) {
			return -1;
		}
		return new Double(getAverage()).compareTo(new Double(g.getAverage()));
	}

	private double[] veriables = {};
	private String id = "";
	private String name = "";
	private double average =0;
	
	public Gene(String data) {
		String[] datas = data.split("\t");
		if (datas.length>0 ) {
			id = datas[0];
		}
		if (datas.length>1 ) {
			name = datas[1];
		}
		if (datas.length>2 ) {
			double sum=0;
			veriables = new double[datas.length-2];
			for (int i=2; i<datas.length; i++) {
				veriables[i-2]= new Double(datas[i]).doubleValue();
				sum+=veriables[i-2];
			}
			average= sum/veriables.length;
		}
	}

	public double[] getVeriables() {
		return veriables;
	}
	
	public double getAverage(){
		return average; 
	}

	public String getId() {
		return id;
	}

	public String getName() {
		return name;
	}	
	
	public String toString() {
		String str= "";
		
		str += getId();
		str += "\t"+getName();
		str += "\t"+ (Math.round(getAverage()*1000.0)/1000.0);

		return str+"\n";
	}
}
